package com.funny.stock.data.controller;

import com.funny.stock.base.util.PageUtil;
import com.funny.stock.base.util.ResultUtil;
import com.funny.stock.base.vo.Result;
import com.funny.stock.data.dao.entity.StockDO;
import com.funny.stock.data.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股票数据通用接口
 *
 * @author pengl
 * @date 2020/11/9
 */
@RestController
@RequestMapping("/stock/common")
public class StockCommonController {

    @Autowired
    StockService stockService;



//    @RequestMapping(value = "/list",method = RequestMethod.GET)
//    public Result getStockList(){
//        return ResultUtil.success(stockService.findAll());
//    }




    @RequestMapping(value = "/queryPageByKey",method = RequestMethod.GET)
    public Result findByCode(@RequestParam String key,
                             @RequestParam(required = false) Integer pageNumber,
                             @RequestParam(required = false) Integer pageSize){
        PageRequest pageRequest = PageUtil.buildPageRequest(pageNumber, pageSize);
        Page<StockDO> page = stockService.findPageByKey(key,pageRequest);

        return ResultUtil.success(page);
    }


}
